//
//  HELPersonInformationVC.m
//  HandheldELearn
//
//  Created by wsj2015 on 2017/1/7.
//  Copyright © 2017年 陈武琦. All rights reserved.
//

#import "HELPersonInformationVC.h"
#import "HELNormalCell.h"
#import "HELIdentityDetalVC.h"

//#import "WCImageView +setImage.h"
@interface HELPersonInformationVC ()

@end

@implementation HELPersonInformationVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)configUI{
  
    self.dataArray = [@[@[@"会员单位"],@[@"手机号码",@"护士执业证",@"真实姓名",@"学历"],@[@"职务",@"技术职称",@"学会职务",@"政治面貌",@"专业分科"]] copy];
    self.tableView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight- 64);
    [self.view addSubview:self.tableView];
    [self.tableView registerNib:[UINib nibWithNibName:@"HELNormalCell" bundle:nil] forCellReuseIdentifier:@"HELNormalCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.title = @"个人中心";
    
    [self requestPersonInfor];
    
    
}

- (void)requestPersonInfor{
    
    cwqHud(self.view);
    weakSelf_define;
    [[HELNetworkManager sharedMg] GET:helPersonInor parameters:nil success:^(id responseObject) {
        
        [hud hide:YES];
        cwqHudSuccess(@"获取成功~");
        [HELAppManager saveUseInfo:responseObject[@"data"]];
        [weakSelf.tableView reloadData];
        
    } failure:^(NSString *err) {
          [hud hide:YES];
        [weakSelf wsj_showLoadFailviewWithRetry:^{
            [weakSelf requestPersonInfor];
        }];
        
    }];

}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return  self.dataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.dataArray[section] count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HELNormalCell *cell =[tableView dequeueReusableCellWithIdentifier:@"HELNormalCell"];
    
    UIView *view = [UIView new];
    view.alpha = .7;
    view.frame = cell.bounds;
    view.backgroundColor = kMainColor;
    cell.selectedBackgroundView =view;
    NSString *title =self.dataArray[indexPath.section][indexPath.row];
    cell.mainTitleL.text = title;
    
    HELUser *user = [HELAppManager userInfo];
    cell.rightTitleL.textColor = kTxtColor;
    cell.rightTitleL.hidden = NO;
    if (indexPath.section == 1) {
        switch (indexPath.row) {
            case 0:{
                //![HELAppManager userInfo].hospitalId
                cell.rightTitleL.text  = user.mobileNumber;
                break;
                }
            case 1:
                cell.rightTitleL.text = user.account;
                break;
            case 2:
                cell.rightTitleL.text =user.realName?user.realName:@"";
                break;
            case 3:{
                cell.rightTitleL.text =user.educationName;
              
                break;
            }
            default:
                break;
        }
    }
     else if (indexPath.section == 2) {
        switch (indexPath.row) {
            case 0:{
                //![HELAppManager userInfo].hospitalId
                cell.rightTitleL.text  = user.nsJob;
                break;
            }
            case 1:
                cell.rightTitleL.text = user.title;
                break;
            case 2:
                cell.rightTitleL.text =user.job;
                break;
            case 3:{
                cell.rightTitleL.text =user.politicalStatusName;
                
                break;
            }
            case 4:{
                cell.rightTitleL.text =user.specialtyDepartment;
                
                break;
            }
            default:
                break;
        }
    }
    
    
    
    else if (indexPath.section==0) {
        cell.rightTitleL.text = user.memberUnitName;
    
        
    }else{
      
    }
    
    return cell;
    
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
   
    if (indexPath.section==0) {
        if (indexPath.row == 0) {
            //[HELAppManager userInfo].hospitalId
            if (1) {
                //已经绑定医院了
                HELIdentityDetalVC *vc =[HELIdentityDetalVC new];
                [self.navigationController pushViewController:vc animated:YES];
            }else{
                //进入绑定页面
//                HELBindIdentyVC *vc =[HELBindIdentyVC new];
//                [self.navigationController pushViewController:vc animated:YES];
            }
        }
       
    }else{
        switch (indexPath.row) {
            case 0:{
                
                 HELNormalCell *cell = (HELNormalCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
                [self getImgPathWithShowCell:cell];
                
                break;
                }
                
        }
    }
    
    
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view =[UIView new];
    view.frame =CGRectMake(0, 0, kScreenWidth, 10);
    view.backgroundColor =[UIColor clearColor];
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 14;
}

- (void)getImgPathWithShowCell:(HELNormalCell *)cell{
    
    
    
//    cwqHud(self.view);
//    weakSelf_define;
//    [[HELNetworkManager sharedMg] GET:kGetQrcodeImg parameters:@{@"userId": [HELAppManager userInfo].userId} success:^(id responseObject) {
//        
//        [hud hideAnimated:YES];
//        if ([responseObject[@"root"] isKindOfClass:[NSString class]] ) {
//            NSRange range = [responseObject[@"root"] rangeOfString:@"http:"];
//            if (range.length) {
//                 [cell.codeImg zoomImageFromUrl:responseObject[@"root"] fromViewController:weakSelf];
//            }
//        }
//      
//    } failure:^(NSString *err) {
//         [hud hideAnimated:YES];
//    }];
    
}

@end
